﻿#coding:UTF-8
require 'rubygems'
require 'watir-webdriver'

browser = Watir::Browser.start 'http://www.12306.cn/mormhweb/kyfw/', :ie

Watir::Wait::until { browser.iframe(:name, 'iframepage').exist?}

sleep(10)

iframepage = browser.iframe(:name, 'iframepage')
iframe = iframepage.iframe(:name, 'main')

fromStationText = iframe.text_field(:id=>"fromStationText")
toStationText = iframe.text_field(:id=>"toStationText")
startdatepicker = iframe.text_field(:id=>"startdatepicker")
startTime = iframe.select_list(:id=>"startTime")
trainCodeText = iframe.text_field(:id=>"trainCodeText")

fromStationText.fire_event('onfocus')
fromStationText.set('BJ')
fromStationText.send_keys :down
fromStationText.send_keys :enter

toStationText.fire_event('onfocus')
toStationText.set('fz')
toStationText.send_keys :enter

startdatepicker.focus
startdatepicker.send_keys :right
startdatepicker.send_keys :right
startdatepicker.send_keys :right
startdatepicker.send_keys :enter

startTime.fire_event("onclick")
startTime.select '00:00--24:00'

trainCodeText.fire_event('onclick')
trainCodeText.send_keys :down
trainCodeText.send_keys :enter

iframe.button(:id=>'submitQuery').fire_event('onclick')
iframe.button(:class=>'yuding_u').fire_event('onclick')
